home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
007
/
cstdio.arc
/
SRC.ARC
/
FNSLONG.A
< prev
next >
Wrap
Text File
|
1984-06-17
|
2KB
|
116 lines
; fnslong.a - intrinsic long arithmetic functions.
; decoded from DeSmet library.
; G. R. Mansfield. 84/06/16.
; Ver 1.0-4616.
dseg
rs: db 0 ; result sign
cseg
public _mod4
public _mul4
public _div4
; mod4 - dx,ax = dx,ax % bx,cx.
_mod4: call _div4
mov dx,si
mov ax,bx
ret
; mul4 - dx,ax = dx,ax * bx,cx.
_mul4: call rrs ; record result sign
mov di,ax
mov ax,dx
mul cx
mov si,ax
mov ax,bx
mul di
add si,ax
mov ax,cx
mul di
add dx,si
; srs - set result sign.
srs: test byte rs,1
jz srs1
not dx
neg ax
sbb dx,0FFFFh
srs1: test byte rs,2
jz srs2
not si
neg bx
sbb si,0FFFFh
srs2: ret
; div 4 - dx,ax = dx,ax / bx,cx.
_div4: call rrs ; record result sign
or bx,bx
jnz div2
cmp cx,dx
jna div1
div cx
xor si,si
mov bx,dx
xor dx,dx
jmp srs ; set result sign
div1: mov bx,ax
mov ax,dx
xor dx,dx
div cx
xchg bx,ax
div cx
xchg dx,bx
xor si,si
jmp srs ; set result sign
div2: push bp
mov bp,cx
mov di,bx
xor si,si
mov bx,si
mov cx,32
div3: shl bx,1
rcl si,1
shl ax,1
rcl dx,1
adc bx,0
sub bx,bp
sbb si,di
inc ax
jnb div4
add bx,bp
adc si,di
dec ax
div4: loop div3
pop bp
jmp srs ; set result sign
; rrs - record result sign.
rrs: mov byte rs,0 ; set positive result
or dx,dx
jns rrs1 ; if dx,ax positive
mov byte rs,3
not dx ; complement dx,ax
neg ax
sbb dx,0FFFFh
rrs1: or bx,bx
jns rrs2
xor byte rs,1
not bx
neg cx
sbb bx,0FFFFh
rrs2: ret